import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */

//常量路由(即所有用户均能访问的路由)
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: 'addProduct',
    name: 'addProduct',
    component: () => import('@/views/commodity/property'),
    meta: { title: '添加商品', icon: 'product-add' },
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
]

//异步路由(放的是权限管理的路由)
export const allAsyncRoutes = [
  // 权限管理
  {
    path: "/authority",
    component: Layout,
    name: "authority",
    meta: { title: "权限管理", icon: "el-icon-user" },
    redirect: "/userList",
    children: [
      {
        path: "userList",
        name:"userList",
        component: () => import("@/views/authority/userList"),
        meta: { title: "用户管理" }
      },
      {
        path: "roleList",
        name:"roleList",
        component: () => import("@/views/authority/roleList"),
        meta: { title: "角色管理" }
      },
      {
        path: "permissionList",
        name:"permissionList",
        component: () => import("@/views/authority/permissionList"),
        meta: { title: "菜单管理" }
      }
    ]
  },
  // 商品管理
  {
    path: '/commodity',
    component: Layout,
    name: 'commodity',
    redirect: '/commodityType',
    children: [{
      path: 'commodityType',
      name: 'commodityType',
      component: () => import('@/views/commodity/commodityType'),
      meta: {
        title: '商品类型',
        icon: 'dashboard'
      }
    }]
  },
  {
    path: '/attribute',
    component: Layout,
    name: 'attribute',
    redirect: '/Attributelist',
    children: [{
      path: 'Attributelist',
      name: 'Attributelist',
      component: () => import('@/views/commodity/attributelist'),
      meta: {
        title: '属性列表',
      },
      hidden: true,
    }]
  },
  {
    path: '/editer',
    component: Layout,
    name: 'editer',
    redirect: '/editerAttribute',
    children: [{
      path: 'EditerAttribute',
      name: 'EditerAttribute',
      component: () => import('@/views/commodity/editerAttribute'),
      meta: {
        title: '修改参数列表',
      },
      hidden: true,
    }]
  },
  // {
  //   path: '/trademark',
  //   component: Layout,
  //   name: 'trademark',
  //   redirect: '/trademark',
  //   children: [{
  //     path: 'trademark',
  //     name: 'trademark',
  //     component: () => import('@/views/commodity/trademark'),
  //     meta: { title: '商品列表', icon: 'dashboard' }
  //   }]
  // },
  {
    path: '/property',
    component: Layout,
    name: 'property',
    redirect: '/property',
    children: [{
      path: 'Property',
      name: 'Property',
      component: () => import('@/views/commodity/property'),
      meta: { title: '添加商品', icon: 'dashboard' }
    }]
  },
  {
    path: '/sku',
    component: Layout,
    name: 'SKU',
    redirect: '/sku',
    children: [{
      path: 'sku',
      name: 'Sku',
      component: () => import('@/views/commodity/SKU'),
      meta: { title: '品牌管理', icon: 'dashboard' }
    },
    {
      path: 'addlist',
      name: 'AddList',
      component: () => import('@/views/commodity/SKU/AddList'),
      meta: { title: '添加商品属性' },
      hidden: true
    },
    {
      path: 'editlist',
      name: 'EditList',
      component: () => import('@/views/commodity/SKU/EditList'),
      meta: { title: '修改商品属性' },
      hidden: true
    }
    ]
  },
  {
    path: '/recommend',
    component: Layout,
    name: 'recommend',
    redirect: '/recommend',
    children: [{
      path: 'recommend',
      name: 'Recommend',
      component: () => import('@/views/commodity/recommend'),
      meta: { title: '品牌推荐', icon: 'dashboard' }
    }]
  },



]

//兜底的404路由
export const anyRoute = { path: '*', redirect: '/404', hidden: true }
const createRouter = () => new Router({
  // mode: 'history', // require service support
  mode: "history",
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
